var actclub_user = require('../model/club_user')
var acttoolv2 = require('../../../xc/sys/toolv2')
Page({
  mixins: [require('../../../xc/mixins/basicMixin')],
  /**
   * 页面的初始数据
   */
  data: {
    actleadgroup: null,
    loading: true,
    billnums:{all:0,notreceived:0,nowriteoff:0,finish:0},
    noticeshow:false,
    popnotice:{
      name:"",
      contant:""
    }
  },
  opscan:function(e){
    var that= this;
      wx.scanCode({
      onlyFromCamera: false,
      success:function(reslut){
        if(reslut['path']){
           wx.redirectTo({
             url: "/"+reslut['path'],
           })
        }
      },
      fail:function(res){
        
      },
      complete:function(com){
      
        
      }
    })  
  },
  xcloaddata: function (options, config) {
    // return
    console.log()
    if(config.yihuo){
      this.setData({
        yihuoconfig:config.yihuo
      })
    }
    this.getnotice()
    //showmodel
    //加载数据完成
  },
  afterlogin: function (options, config, userinfo) {
    if (config.club.status != 1) {
      wx.redirectTo({
        url: config.basic.homeurl,
      })
      return
    }

    this.data.homeurl = config.basic.homeurl
    var app = getApp()
    var that = this;
    app.xc_sys_config.authop.oppower("login").then(function (res) {
      that.centerinfo()
      if (res["status"] == 1) {
        var memberinfo = res["obj"]["memberinfo"]
        that.setData({ memberinfo })
      }
  
      // that.setData({ "member": app.globalData.member,configclub:config.club })    
    })
    //cashoutcom
  },
  onNoticeClose(){
    var popnotice={
       name:"",
       contant:""
     }
      this.setData({
       popnotice:popnotice,
       noticeshow:false
      })
   },
   shownoticedetail(e){
  
     var dataset=e.currentTarget.dataset;
     var popnotice={
       name:dataset.item.name,
       contant:dataset.item.contents,
     }
     this.setData({
       noticeshow:true,
       popnotice:popnotice
     })
   },
   //分销通知列表
   getnotice(){
     var that = this
     actclub_user.getnotice().then(function (rst) {
       if(rst['status']==1){
         that.setData({ noticelist: rst['obj'] })
       }
     })
   },
  showqr:function(){
    var widgetsshare =this.selectComponent("#widgetsshare");
    widgetsshare.showSharefunc()
  },
  withdrawal:function(){
    var that = this 
    if(this.data.actleadgroup)
    {
      var cashoutcom= that.selectComponent("#cashoutcom");
      cashoutcom.showmodel('club');
    }
    else
    {
      wx.showToast({
        title: '等待数据加载',
      })
    }   
  },
  cashoutrecord:function(e){
    var app =getApp();
    if(app.globalData.actleadgroup)
    {
      var cashoutrecord= this.selectComponent("#cashoutrecord");
      cashoutrecord.showmodel('club',app.globalData.actleadgroup.id);
    }
  },
  aftercashout:function(e){
//提现之后更新

    var reslut=e.detail   
   var app =getApp();
   app.globalData.actleadgroup.brokerage  =reslut.brokerage
    this.setData({"actleadgroup.brokerage":app.globalData.actleadgroup.brokerage})
   },

  centerinfo() {
    var that = this
    actclub_user.centerinfo().then(res => {
      if (res["status"] == 1) {
        var mygroups = res["obj"]["mygroups"]
        if (mygroups) {
          var actleadgroup = actclub_user.initleadgroup(mygroups)
         
          if(actleadgroup){
           var isclub= actclub_user.applystatus(that,actleadgroup)   //判断状态，是滞审核通过
           if(isclub){
             that.loadstatus(false)
           }
           //团长信息         
           var clubcount=res["obj"]["clubcount"]  
           var billnums={all:0,notreceived:0,nowriteoff:0,nowdeliver:0,delivering:0,finish:0};
           var mappingfield={undeliver:"0",notreceived:"1",nowriteoff:"2",finish:"3",nowdeliver:"4",delivering:"5"} //订单状态对应的结果
      
           if(clubcount)
           {
             var totalnum=0;
            for(var a in mappingfield){
              if(clubcount[mappingfield[a]]){
                billnums[a]=clubcount[mappingfield[a]]['mum']
                totalnum += parseInt(clubcount[mappingfield[a]]['mum']) 
              }            
            }
            billnums["all"]=totalnum
           } 
     
        
           that.setData({actleadgroup,billnums})    
           return;
          }        
        }

     
        wx.redirectTo({
          url: "/xc_lshop/club/info/apply",
        })
        
      }
    })
  },
   
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  mapnavigation() {
    var app = getApp()
    var latitude = parseFloat(app.globalData.clubinfo.lat)
    var longitude = parseFloat(app.globalData.clubinfo.lng)
    wx.openLocation({
      latitude,
      longitude,
      scale: 18
    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  
})